<?php

include _ITSTOCK_INCLUDE_DIR_.'html_search.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_message.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_navigation.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_links.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_menu.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_table_list.inc.php';

$itstock_page_info['css'] = array('main.css', 'aside.css', 'float_menu.css', 'page.css', 'table.css', 'lightbox.css', 'form_save.css');
$itstock_page_info['js'] = array('common.js', 'ajax.js', 'request.js', 'lightbox.js', 'search.js', 'settings.js');
$itstock_page_info['title'] = 'Locations - IT Stock Tool';
$itstock_page_info['menu_title'] = 'Locations';
$itstock_page_info['menu_items'] = array('<label onclick="itstock_page_request(\'add_location\')">New Location</label>');
$itstock_page_info['search_page'] = 'location';

$_SESSION['on_delete']['location'] = $_SERVER['REQUEST_URI'];
$_SESSION['on_save']['location'] = $_SERVER['REQUEST_URI'];

$structure = itstock_html_search_init('location');
$structure['table_headers'] = array('Building', 'Department', 'Floor', 'Spot', 'Name', '', '', '');
$structure['table_indexes'] = array('building', 'department', 'floor', 'spot', 'location');
$structure['table_actions'] = array(
  array( 'link' => 'main.php?page=hardware_location&id=%s', 'img' => 'img/hardware.png', 'title' => 'See Hardware', 'id' => 'id'),
  array( 'img' => 'img/edit.png', 'onclick' => 'itstock_page_request(\'add_location\', \'%s\')', 'title' => 'Edit', 'id' => 'id' ),
  array( 'link' => 'delete.php?type=location&id=%s', 'img' => 'img/delete.png', 'title' => 'Delete', 'id' => 'id')
);
$structure['table_error'] = 'No locations have been found.';

itstock_structure($bldg, 'building');
$menu_title = array(
  'text' => 'All Buildings',
  'url' => '?page=location'
);
$bldg_get = $_GET;
if(isset($bldg_get['idx'])) unset($bldg_get['idx']);
if(isset($bldg_get['search'])) unset($bldg_get['search']);
if(isset($_GET['bldg'])) {
  $dept_get = $bldg_get;
  $structure['where'][0] = 'building_id='.itstock_decode($_GET['bldg']);
  itstock_structure($dpt, 'department');
  $dpt['where'][0] = 'building_id='.itstock_decode($_GET['bldg']);
  if(isset($_GET['dept'])) {
    unset($bldg_get['dept']);
    $structure['where'][0] = 'department_id='.itstock_decode($_GET['dept']);
    unset($structure['table_headers'][1]);
    unset($structure['table_indexes'][1]);
  }
  unset($structure['table_headers'][0]);
  unset($structure['table_indexes'][0]);
}

itstock_html_base_header($itstock_page_info);
echo '<div class="aside">';
itstock_html_menu_struct($bldg, 'building', 'id', 'bldg', '', $menu_title, $bldg_get);
if(isset($_GET['bldg'])) {
  $menu_title['text'] = 'All Departments';
  $menu_title['url'] = $menu_title['url'] . '&bldg='.$_GET['bldg'];
  itstock_html_menu_struct($dpt, 'department', 'id', 'dept', '', $menu_title, $dept_get);
}

echo '</div>';
echo '<div class="bside">';
itstock_html_menu_search($itstock_page_info);
echo '<table>';
itstock_html_table_list_data($structure, false, true, true);
echo '</table>';
echo '</div>';
itstock_html_base_footer();
?>
